package com.yequan.thread.threadlocal;

import java.util.concurrent.TimeUnit;

/**
 * @author : Administrator
 * @date : 2020/10/2
 */
public class ThreadLocalDemo {

    public static ThreadLocal<String> threadLocal = new ThreadLocal<>();
    public static ThreadLocal<String> threadLocal2 = new ThreadLocal<>();

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            int finalI = i;
            new Thread(() -> {
                try {
                    threadLocal.set("T-" + finalI);
                    threadLocal2.set("hhhhh");
                    System.out.println("1111" + threadLocal.get());
                    System.out.println("2222" + threadLocal2.get());
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }

}
